package fr.znight.chacunsatv.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class PrefsHelper {
	public static final String PREFS_NAME = "MyPrefsFile";

	public static final String FAV_APP_COUNT = "FAV_APP_COUNT";
	public static final String FAV_APP_KEY_PREFIX = "FAV_APP_KEY_PREFIX_";

	public static boolean containsKey(Context context, String key)
	{
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		return settings.contains(key);
	}

	public static String getString(Context context, String key)
	{
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		return settings.getString(key, "");
	}

	public static void setString(Context context, String key, String value)
	{
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		Editor editor = settings.edit();
		editor.putString(key, value);
		editor.commit();
	}

	public static boolean getBoolean(Context context, String key)
	{
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		return settings.getBoolean(key, false);
	}

	public static void setBoolean(Context context, String key, boolean value)
	{
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		Editor editor = settings.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}

	public static int getInt(Context context, String key)
	{
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		return settings.getInt(key, 0);
	}

	public static void setInt(Context context, String key, int value)
	{
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		Editor editor = settings.edit();
		editor.putInt(key, value);
		editor.commit();
	}

	public static void deleteKey(Context context, String key)
	{
		if (containsKey(context, key))
		{
			SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
			Editor editor = settings.edit();
			editor.remove(key);
			editor.commit();
		}
	}
	
	public static void cleanSettings(Context context)
	{
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		Editor editor = settings.edit();
		editor.clear();
		editor.commit();
	}
}
